﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VRAEWeb.Models;

namespace VRAEWeb.Controllers
{
    public class PagoServicioController : Controller
    {
        //
        // GET: /PagoServicio/
        public ActionResult Index()
        {
            VRAEBancoModeloDataContext db = new VRAEBancoModeloDataContext();
            
            ViewData["Cuentas"] = new SelectList((from e in db.Cuenta
                                                    where e.IdCliente.Equals(1)
                                                    select e), "NumeroCuenta", "NumeroCuenta");

            ViewData["Empresas"] = new SelectList((from e in db.Empresa
                                                    select e), "IdEmpresa", "RazonSocial");

            ViewData["Servicios"] = new SelectList((from e in db.Servicio
                                                    select e), "IdServicio", "Descripcion");
            
            return View();
        }

        [HttpPost]
        public ActionResult Index(FormCollection formCollection)
        {
            String sCodigo = formCollection["codigo"];

            Int32 idEmpresa = Int32.Parse(formCollection["Empresas"].ToString());
            Int32 idServicio = Int32.Parse(formCollection["Servicios"].ToString());

            Session["Cuentas"] = formCollection["Cuentas"];
            Session["Empresas"] = idEmpresa;
            Session["Servicios"] = idServicio;

            String sControler = string.Empty;

            switch (idEmpresa)
            {
                case 4:
                    switch (idServicio)
                    {
                        case 1:
                            sControler = "PagoArbitrio";
                            break;
                        case 2:
                            sControler = "PagoPredial";
                            break;
                        case 3:
                            sControler = "PagoVarios";
                            break;
                    }
                    break;
            }
            
            if (sControler != string.Empty)
                return RedirectToAction("Index", sControler, new { sCodigoContribuyente = sCodigo });
            else
                return RedirectToAction("Index");
        }
    }
}
